﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using Syncfusion.Windows.Forms.Grid;
using System.Collections.Specialized;

using nStruct;


namespace nGrid
{
	class cGrid
	{
		public static void Calc_Warning_and_Protection_Status(PS_Conf_Struct inDat)
		{
			//for (int i = 0; i < 120; i++)
			//{
			//    inDat.HW_I_Status[i] = 0;
			//}
			for (int i = 0; i < inDat.HW_No; i++)
			{
				inDat.HW_I_Status[i] = 0;//noramal
				if (inDat.HW_I_Value[i] > inDat.HW_IProtect[i]) inDat.HW_I_Status[i] = 2;
				if (inDat.PsEn[i] == 0) inDat.HW_I_Status[i] = 0;
			}

			for (int i = 0; i < inDat.TempNo; i++)
			{
				inDat.Temp_Status[i] = 0;//noramal
				if (inDat.Temp_Value[i] > inDat.TempProtect[i]) inDat.Temp_Status[i] = 2;
				if (inDat.TempEn[i] == 0) inDat.Temp_Status[i] = 0;
			}
		}
		public static void MainForm_Information_Grid_Write_Monitor(int key, Syncfusion.Windows.Forms.Grid.GridControl inGrid, PS_Conf_Struct inDat)
		{
			int ch;
			if (key == 0)
			{
				ch = inDat.PsSelectCh;
				inGrid[inGrid.RowCount, 2].Text = string.Format("{0:0.0}", inDat.HW_I_Value[ch]);
			}
			else
			{
				ch = inDat.TempSelectCh;
				inGrid[inGrid.RowCount, 2].Text = string.Format("{0:0}", inDat.Temp_Value[ch]);
			}
		}

		public static void MainForm_Information_Grid_Write(int key, Syncfusion.Windows.Forms.Grid.GridControl inGrid, PS_Conf_Struct inDat, Select_Struct inSelect)
		{
			if (key == 0)
			{
				int ch;
				ch = inSelect.PS_HW_CH;


				switch (inSelect.PS_Group)
				{
					case 0: inGrid[2, 2].Text = "A"; inGrid[2, 2].BackColor = Color.LightCoral; break;
					case 1: inGrid[2, 2].Text = "B"; inGrid[2, 2].BackColor = Color.LightGoldenrodYellow; break;
					case 2: inGrid[2, 2].Text = "C"; inGrid[2, 2].BackColor = Color.LightSalmon; break;
				}

				

				inGrid[3, 2].Text = inDat.HW_PsName[ch];// "PS " + (ch + 1).ToString();
				inGrid[4, 2].Text = (inDat.HW_PsStringIndex[ch] + 1).ToString() + " / " + inDat.StringNo[ch].ToString();
				inGrid[5, 2].Text = inDat.Vset[ch].ToString();
				inGrid[6, 2].Text = inDat.Iset[ch].ToString();
				inGrid[7, 2].Text = inDat.IProtect[ch].ToString();
				inGrid[8, 2].Text = inDat.HW_I_Value[ch].ToString();
			}
			else
			{
				int ch = inSelect.Temp_Channel;
				switch (inSelect.Temp_Group)
				{
					case 0: inGrid[10, 2].Text = "A"; inGrid[10, 2].BackColor = Color.LightCoral; break;
					case 1: inGrid[10, 2].Text = "B"; inGrid[10, 2].BackColor = Color.LightGoldenrodYellow;  break;
					case 2: inGrid[10, 2].Text = "C"; inGrid[10, 2].BackColor = Color.LightSalmon; break ;
				}

				inGrid[11, 2].Text = inDat.TempName[ch];// "Temp " + (ch + 1).ToString();
				inGrid[12, 2].Text = inDat.TempProtect[ch].ToString();
				inGrid[13, 2].Text = inDat.Temp_Value[ch].ToString();
			}
		}



		public static void MainForm_Information_Grid_Create(int key, Syncfusion.Windows.Forms.Grid.GridControl inGrid)
		{

			inGrid.RowCount = 13;
			inGrid.ColCount = 2;
			inGrid.Properties.RowHeaders = false;
			inGrid.Properties.ColHeaders = false;
			inGrid.DefaultRowHeight = 20;


			inGrid.ColWidths[1] = 160;
			inGrid.ColWidths[2] = 100;


			for (int i = 1; i <= inGrid.RowCount; i++)
			{
				for (int j = 1; j <= inGrid.ColCount; j++)
				{
					inGrid[i, j].VerticalAlignment = Syncfusion.Windows.Forms.Grid.GridVerticalAlignment.Middle;
					inGrid[i, j].HorizontalAlignment = Syncfusion.Windows.Forms.Grid.GridHorizontalAlignment.Center;
				}
			}

			for (int j = 0; j < inGrid.ColCount; j++)
			{
				for (int i = 0; i < inGrid.RowCount; i++)
				{
					inGrid[i + 1, j + 1].CellType = "Static";
					inGrid[i + 1, j + 1].VerticalAlignment = Syncfusion.Windows.Forms.Grid.GridVerticalAlignment.Middle;
					if (j == 1) inGrid[i + 1, j + 1].HorizontalAlignment = Syncfusion.Windows.Forms.Grid.GridHorizontalAlignment.Center;
					else inGrid[i + 1, j + 1].HorizontalAlignment = Syncfusion.Windows.Forms.Grid.GridHorizontalAlignment.Left;
				}
			}

			inGrid.RowHeights[1] = 25;

			inGrid.CoveredRanges.AddRange(new Syncfusion.Windows.Forms.Grid.GridRangeInfo[] {
            Syncfusion.Windows.Forms.Grid.GridRangeInfo.Cells(1, 1, 1, 2)});
			inGrid.CoveredRanges.AddRange(new Syncfusion.Windows.Forms.Grid.GridRangeInfo[] {
            Syncfusion.Windows.Forms.Grid.GridRangeInfo.Cells(9, 1, 9, 2)});


			for (int i = 0; i < inGrid.RowCount; i++) inGrid[i + 1, 1].BackColor = Color.LightCyan;
			for (int i = 0; i < inGrid.RowCount; i++) inGrid[i + 1, 2].BackColor = Color.White;

			inGrid[1, 1].Text = "P/S Channel information";
			inGrid[1, 1].BackColor = Color.ForestGreen;
			
			inGrid[2, 1].Text = "Group";
			inGrid[3, 1].Text = "Channel Name";
			inGrid[4, 1].Text = "String No";
			inGrid[5, 1].Text = "Set Voltage(V)";
			inGrid[6, 1].Text = "Set Current(mA))";
			inGrid[7, 1].Text = "Protect(mA)";
			inGrid[8, 1].Text = "Current Monitor(mA)";


			inGrid[9, 1].Text = "Temp Channel Informations";
			inGrid[9, 1].BackColor = Color.ForestGreen;
			inGrid[10, 1].Text = "Group";
			inGrid[11, 1].Text = "Temp Name";
			inGrid[12, 1].Text = "Protection";
			inGrid[13, 1].Text = "Temp Value";

			inGrid[8, 2].BackColor = Color.Beige;
			inGrid[13, 2].BackColor = Color.Beige;

		}


		public static void SetupForm_PS_Grid_Read(Syncfusion.Windows.Forms.Grid.GridControl inGrid, ref PS_Conf_Struct inDat)
		{
			int add;
			for (int i = 0; i < inGrid.RowCount; i++)
			{
				add = 1;
				inDat.PsEn[i] = Convert.ToInt32(inGrid[1 + i, add++].Text);
				inDat.StringNo[i] = Convert.ToInt32(inGrid[1 + i, add++].Text);
				inDat.PsName[i] = inGrid[1 + i, add++].Text;
				inDat.Vset[i] = Convert.ToSingle(inGrid[1 + i, add++].Text);
				inDat.Iset[i] = Convert.ToSingle(inGrid[1 + i, add++].Text);
				inDat.IProtect[i] = Convert.ToSingle(inGrid[1 + i, add++].Text);
			}

		}

		public static void SetupForm_PS_Grid_ErrorCheck(Syncfusion.Windows.Forms.Grid.GridControl inGrid)
		{

			for (int i = 0; i < inGrid.RowCount; i++)
			{
				for (int j = 0; j < inGrid.ColCount; j++) inGrid[i + 1, j + 1].TextColor = Color.Black;
			}

			int sumPS = 0;
			for (int i = 0; i < inGrid.RowCount; i++)
			{
				if (inGrid[i + 1, 1].Text == "1") sumPS += Convert.ToInt32(inGrid[i + 1, 2].Text);
			}
			if (sumPS > 40)
			{
				for (int i = 0; i < inGrid.RowCount; i++) inGrid[i + 1, 2].TextColor = Color.Red;
			}
			else
			{
				for (int i = 0; i < inGrid.RowCount; i++) inGrid[i + 1, 2].TextColor = Color.Black;

			}



			//2 동일 Name 확인
			string nName = "";

			for (int i = 0; i < inGrid.RowCount; i++)
			{
				nName = inGrid[i + 1, 3].Text;
				if (inGrid[i + 1, 1].Text == "1")
				{
					for (int j = 0; j < inGrid.RowCount; j++)
					{
						if (i != j && inGrid[j + 1, 1].Text == "1" && nName == inGrid[j + 1, 3].Text) inGrid[j + 1, 3].TextColor = Color.Red;
					}
				}
			}


			//3 Vset가 150V 이상인가?

			for (int i = 0; i < inGrid.RowCount; i++)
			{
				if (inGrid[i + 1, 1].Text == "1" && Convert.ToSingle(inGrid[i + 1, 4].Text) > 150) inGrid[i + 1, 4].TextColor = Color.Red;
				//else inGrid[i + 1, 4].TextColor = Color.Black;
			}

			//4 Iset가 500mA 이상인가?
			for (int i = 0; i < inGrid.RowCount; i++)
			{
				if (inGrid[i + 1, 1].Text == "1" && Convert.ToSingle(inGrid[i + 1, 5].Text) > 500) inGrid[i + 1, 5].TextColor = Color.Red;
				//else inGrid[i + 1, 5].TextColor = Color.Black;
			}

			//5 Warning Lower가 Iset보다 큰가
			float iSet = 0;
			float iProtect = 0;
			/*
			for (int i = 0; i < inGrid.RowCount; i++)
			{
				iSet = Convert.ToSingle(inGrid[i + 1, 5].Text);
				iWarn_Lower = Convert.ToSingle(inGrid[i + 1, 6].Text);
				if (inGrid[i+1,1].Text =="1" && iSet < iWarn_Lower) inGrid[i + 1, 6].TextColor = Color.Red;
				//else inGrid[i + 1, 6].TextColor = Color.Black;
			}

			//6 Warning Upper가 Iset보다 작은가
			float iWarn_Upper = 0;
			for (int i = 0; i < inGrid.RowCount; i++)
			{
				iSet = Convert.ToSingle(inGrid[i + 1, 5].Text);
				iWarn_Upper = Convert.ToSingle(inGrid[i + 1, 7].Text);
				if (inGrid[i+1,1].Text =="1" && iSet > iWarn_Upper) inGrid[i + 1, 7].TextColor = Color.Red;
				//else inGrid[i + 1, 7].TextColor = Color.Black;
			}*/
			/*
			//7 Protect Lower가 Iset보다 큰가
			float iProtect_Lower = 0;
			for (int i = 0; i < inGrid.RowCount; i++)
			{
				iSet = Convert.ToSingle(inGrid[i + 1, 5].Text);
				iProtect_Lower = Convert.ToSingle(inGrid[i + 1, 8].Text);
				if (inGrid[i+1,1].Text =="1" && iSet < iProtect_Lower) inGrid[i + 1, 8].TextColor = Color.Red;
				//else inGrid[i + 1, 8].TextColor = Color.Black;
			}

			//8 Protect Upper가 Iset보다 작은가
			float iProtect_Upper = 0;
			for (int i = 0; i < inGrid.RowCount; i++)
			{
				iSet = Convert.ToSingle(inGrid[i + 1, 5].Text);
				iProtect_Upper = Convert.ToSingle(inGrid[i + 1, 9].Text);
				if (inGrid[i+1,1].Text =="1" && iSet > iProtect_Upper) inGrid[i + 1, 9].TextColor = Color.Red;
				//else inGrid[i + 1, 9].TextColor = Color.Black;
			}
			
			//9 Warning Lower가 Protect Lower 보다 큰가
			for (int i = 0; i < inGrid.RowCount; i++)
			{
				iWarn_Lower = Convert.ToSingle(inGrid[i + 1, i].Text);
				iProtect_Lower = Convert.ToSingle(inGrid[i + 1, 7].Text);
				if (inGrid[i+1,1].Text =="1" && iWarn_Lower < iProtect_Lower) inGrid[i + 1, 8].TextColor = Color.Red;
				//else inGrid[i + 1, 8].TextColor = Color.Black;
			}
			*/
			//10 Warning Upper가 Protect Upper 보다 작은가
			for (int i = 0; i < inGrid.RowCount; i++)
			{
				iSet = Convert.ToSingle(inGrid[i + 1, 5].Text);
				iProtect = Convert.ToSingle(inGrid[i + 1, 6].Text);
				if (inGrid[i + 1, 1].Text == "1" && iSet > iProtect) inGrid[i + 1, 6].TextColor = Color.Red;
			}

		}


		public static void SetupForm_Temp_Grid_ErrorCheck(Syncfusion.Windows.Forms.Grid.GridControl inGrid)
		{

			for (int i = 0; i < inGrid.RowCount; i++)
			{
				for (int j = 0; j < inGrid.ColCount; j++) inGrid[i + 1, j + 1].TextColor = Color.Black;
			}



			//2 동일 Name 확인
			string nName = "";

			for (int i = 0; i < inGrid.RowCount; i++)
			{
				nName = inGrid[i + 1, 2].Text;
				if (inGrid[i + 1, 1].Text == "1")
				{
					for (int j = 0; j < inGrid.RowCount; j++)
					{
						if (i != j && inGrid[j + 1, 1].Text == "1" && nName == inGrid[j + 1, 2].Text) inGrid[j + 1, 2].TextColor = Color.Red;
					}
				}
			}



			//1 I Set이 Protect보다 큰가
			/*float iProtect = 0;
			float iSet = 0;

			for (int i = 0; i < inGrid.RowCount; i++)
			{
				iSet = Convert.ToSingle(inGrid[i + 1, 3].Text);
				iProtect = Convert.ToSingle(inGrid[i + 1, 4].Text);

				if (inGrid[i + 1, 1].Text == "1" && iSet > iProtect) inGrid[i + 1, 4].TextColor = Color.Red;
				//else inGrid[i + 1, 6].TextColor = Color.Black;
			}*/
		}


		public static void SetupForm_Temp_Grid_Read(Syncfusion.Windows.Forms.Grid.GridControl inGrid, ref PS_Conf_Struct inDat)
		{
			for (int i = 0; i < inGrid.RowCount; i++)
			{
				inDat.TempEn[i] = Convert.ToInt32(inGrid[1 + i, 1].Text);
				inDat.TempName[i] = inGrid[1 + i, 2].Text;
				inDat.TempProtect[i] = Convert.ToByte(inGrid[1 + i, 3].Text);
			}
		}

		public static void SetupForm_PS_Grid_Create(Syncfusion.Windows.Forms.Grid.GridControl inGrid, PS_Conf_Struct inDat)
		{

			int add = 0;
			StringCollection items = new StringCollection();
			for (int i = 0; i < 40; i++) items.Add((i + 1).ToString());


			inGrid.ColCount = 6;
			inGrid.RowCount = inDat.PsNo;
			inGrid.Properties.RowHeaders = false;
			inGrid.DefaultRowHeight = 25;

			inGrid.ColWidths[1] = 30;
			inGrid.ColWidths[2] = 60;
			inGrid.ColWidths[3] = 120;//name
			inGrid.ColWidths[4] = 100;
			inGrid.ColWidths[5] = 100;
			inGrid.ColWidths[6] = 100;

			for (int i = 0; i < inDat.PsNo; i++)
			{
				inGrid[i + 1, 1].CellType = "CheckBox";
				inGrid[i + 1, 2].CellType = "ComboBox";
				inGrid[i + 1, 2].ChoiceList = items;
				inGrid[i + 1, 2].DropDownStyle = GridDropDownStyle.Exclusive;
				for (int j = 0; j < 3; j++) inGrid[i + 1, 3 + j].CellType = "TextBox";
			}

			inGrid.RowHeights[0] = 50;
			for (int j = 0; j < inGrid.ColCount; j++)
			{
				for (int i = 0; i < inGrid.RowCount; i++)
				{
					inGrid[i + 1, j + 1].VerticalAlignment = Syncfusion.Windows.Forms.Grid.GridVerticalAlignment.Middle;
					inGrid[i + 1, j + 1].HorizontalAlignment = Syncfusion.Windows.Forms.Grid.GridHorizontalAlignment.Center;
				}
			}


			add = 1;
			inGrid[0, add++].Text = "En";
			inGrid[0, add++].Text = "String No";
			inGrid[0, add++].Text = "Name";
			inGrid[0, add++].Text = "Voltage(V)";
			inGrid[0, add++].Text = "Current(mA)";
			inGrid[0, add++].Text = "Protect Limit";

			SetupForm_PS_Grid_Write(inGrid, inDat);

		}

		public static void SetupForm_PS_Grid_Write(Syncfusion.Windows.Forms.Grid.GridControl inGrid, PS_Conf_Struct inDat)
		{

			for (int i = 0; i < inGrid.RowCount; i++)
			{
				if (inDat.PsEn[i] == 1)
				{
					inGrid[i + 1, 1].Text = "1";

					inGrid[i + 1, 2].Text = inDat.StringNo[i].ToString();
					for (int j = 2; j < inGrid.ColCount; j++)
					{
						inGrid[i + 1, 1 + j].BackColor = Color.White;
						inGrid[i + 1, 1 + j].CellType = "TextBox";
					}
				}
				else
				{
					inGrid[i + 1, 1].Text = "0";
					inGrid[i + 1, 2].Text = "1";
					for (int j = 2; j < inGrid.ColCount; j++)
					{
						inGrid[i + 1, 1 + j].BackColor = Color.LightGray;
						inGrid[i + 1, 1 + j].CellType = "Static";
					}
				}

				inGrid[i + 1, 3].Text = inDat.PsName[i];

				inGrid[i + 1, 4].Text = inDat.Vset[i].ToString();
				inGrid[i + 1, 5].Text = inDat.Iset[i].ToString();
				//inGrid[i + 1, 6].Text = inDat.IWarning_Lower[i].ToString();
				//inGrid[i + 1, 7].Text = inDat.IWarning_Upper[i].ToString();
				//inGrid[i + 1, 8].Text = inDat.IProtect_Lower[i].ToString();
				inGrid[i + 1, 6].Text = inDat.IProtect[i].ToString();

			}
		}

		public static void MainForm_PS_Grid_Create(Syncfusion.Windows.Forms.Grid.GridControl inGrid)
		{

			int colNo = 10;
			int rowNo = 12;//(40/10)*3

			inGrid.ColCount = colNo;
			inGrid.RowCount = rowNo * 2;

			inGrid.Properties.RowHeaders = true;
			inGrid.Properties.ColHeaders = false;
			inGrid.DefaultRowHeight = 35;


			for (int i = 0; i <= colNo; i++) inGrid.ColWidths[i] = 80;

			for (int i = 0; i < inGrid.RowCount; i++)
			{
				inGrid[i + 1, 0].VerticalAlignment = Syncfusion.Windows.Forms.Grid.GridVerticalAlignment.Middle;
				inGrid[i + 1, 0].HorizontalAlignment = Syncfusion.Windows.Forms.Grid.GridHorizontalAlignment.Center;

			}

			for (int j = 0; j < inGrid.ColCount; j++)
			{
				for (int i = 0; i < inGrid.RowCount; i++)
				{
					inGrid[i + 1, j + 1].CellType = "Static";
					inGrid[i + 1, j + 1].VerticalAlignment = Syncfusion.Windows.Forms.Grid.GridVerticalAlignment.Middle;
					inGrid[i + 1, j + 1].HorizontalAlignment = Syncfusion.Windows.Forms.Grid.GridHorizontalAlignment.Center;
					inGrid[i + 1, j + 1].BackColor = Color.LightCyan;
				}
			}

			inGrid.Model.CoveredRanges.Clear();
			//merge
			inGrid.ColWidths[0] = 120;


			inGrid.CoveredRanges.AddRange(new Syncfusion.Windows.Forms.Grid.GridRangeInfo[] {
            Syncfusion.Windows.Forms.Grid.GridRangeInfo.Cells(1, 0, 8, 0)});
			inGrid[1, 0].Text = "A Group";
			inGrid[1, 0].BackColor = Color.LightCoral;

			inGrid.CoveredRanges.AddRange(new Syncfusion.Windows.Forms.Grid.GridRangeInfo[] {
            Syncfusion.Windows.Forms.Grid.GridRangeInfo.Cells(1+8, 0, 8+8, 0)});
			inGrid[1 + 8, 0].Text = "B Group";
			inGrid[1 + 8, 0].BackColor = Color.LightGoldenrodYellow;

			inGrid.CoveredRanges.AddRange(new Syncfusion.Windows.Forms.Grid.GridRangeInfo[] {
            Syncfusion.Windows.Forms.Grid.GridRangeInfo.Cells(1+8+8, 0, 8+8+8, 0)});
			inGrid[1 + 8 + 8, 0].Text = "C Group";
			inGrid[1 + 8 + 8, 0].BackColor = Color.LightSalmon;
			//int ps_no = 0;
			for (int i = 0; i < rowNo; i++)
			{
				for (int j = 0; j < colNo; j++)
				{

					inGrid[i * 2 + 1, j + 1].BackColor = Color.LightCyan;
					inGrid[i * 2 + 2, j + 1].BackColor = Color.White;
				}
			}

		}

		public static void MainForm_PS_Grid_Create_Name(int key, Syncfusion.Windows.Forms.Grid.GridControl inGrid, PS_Conf_Struct inDat)
		{

			int M_row = key * 8;
			int ps_no = 0;
			for (int i = 0; i < 4; i++)
			{
				for (int j = 0; j < inGrid.ColCount; j++)
				{

					if (inDat.HW_PsEn[ps_no] == 1)
					{
						inGrid[M_row + i * 2 + 1, j + 1].Text = inDat.HW_PsName[ps_no];// "PS " + (ps_no + 1).ToString();
						inGrid[M_row + i * 2 + 1, j + 1].BackColor = Color.LightCyan;
						inGrid[M_row + i * 2 + 2, j + 1].BackColor = Color.White;
					}
					else
					{

						inGrid[M_row + i * 2 + 1, j + 1].Text = "";
						inGrid[M_row + i * 2 + 1, j + 1].BackColor = Color.LightGray;
						inGrid[M_row + i * 2 + 2, j + 1].BackColor = Color.LightGray;
					}
					ps_no++;
					
				}

			}

		}


		public static void MainForm_PS_Grid_Write(int key, Syncfusion.Windows.Forms.Grid.GridControl inGrid, PS_Conf_Struct inDat)
		{
			int M_row = key * 8;
			int ps_no = 0;
			int colNo = 10;
			int row = 0;
			for (int i = 0; i < 4; i++)
			{
				row = i * 2 + 2;
				for (int j = 0; j < colNo; j++)
				{

					if (inDat.HW_PsEn[ps_no] == 1)
					{
						inGrid[row, j + 1].Text = string.Format("{0:0.0}", inDat.HW_I_Value[ps_no]);
						switch (inDat.HW_I_Status[ps_no])
						{
							case 0://normal
								inGrid[row, j + 1].BackColor = Color.White;
								break;
							case 1://warning
								inGrid[row, j + 1].BackColor = Color.Yellow;
								break;
							case 2://protect
								inGrid[row, j + 1].BackColor = Color.Red;
								break;
						}
					}
					else
					{
						inGrid[row, j + 1].Text = "0.0";
						inGrid[row, j + 1].BackColor = Color.LightGray;
					}
					ps_no++;
					//if (ps_no >= inDat.HW_No) break;
				}
			}
		}

		public static void MainForm_Temp_Grid_Create(Syncfusion.Windows.Forms.Grid.GridControl inGrid)
		{

			int colNo = 8;
			int rowNo = 6;

			inGrid.ColCount = colNo;
			inGrid.RowCount = rowNo * 2;



			inGrid.Properties.RowHeaders = true;
			inGrid.Properties.ColHeaders = false;
			inGrid.DefaultRowHeight = 35;

			for (int i = 0; i <= colNo; i++) inGrid.ColWidths[i] = 80;


			for (int j = 0; j < inGrid.ColCount; j++)
			{
				for (int i = 0; i < inGrid.RowCount; i++)
				{
					inGrid[i + 1, j + 1].CellType = "Static";
					inGrid[i + 1, j + 1].VerticalAlignment = Syncfusion.Windows.Forms.Grid.GridVerticalAlignment.Middle;
					inGrid[i + 1, j + 1].HorizontalAlignment = Syncfusion.Windows.Forms.Grid.GridHorizontalAlignment.Center;

				}
			}

			for (int i = 0; i < inGrid.RowCount; i++)
			{
				inGrid[i + 1, 0].VerticalAlignment = Syncfusion.Windows.Forms.Grid.GridVerticalAlignment.Middle;
				inGrid[i + 1, 0].HorizontalAlignment = Syncfusion.Windows.Forms.Grid.GridHorizontalAlignment.Center;
			}



			inGrid.Model.CoveredRanges.Clear();
			//merge
			inGrid.ColWidths[0] = 120;

			inGrid.Model.CoveredRanges.Add(GridRangeInfo.Cells(1, 0, 4, 0));
			inGrid[1, 0].Text = "A Temp";
			inGrid[1, 0].BackColor = Color.LightCoral;
			inGrid.Model.CoveredRanges.Add(GridRangeInfo.Cells(5, 0, 8, 0));
			inGrid[5, 0].Text = "B Temp";
			inGrid[5, 0].BackColor = Color.LightGoldenrodYellow;
			inGrid.Model.CoveredRanges.Add(GridRangeInfo.Cells(9, 0, 12, 0));
			inGrid[9, 0].Text = "C Temp";
			inGrid[9, 0].BackColor = Color.LightSalmon;

			for (int i = 0; i < rowNo; i++)
			{
				for (int j = 0; j < colNo; j++)
				{

					inGrid[i * 2 + 1, j + 1].BackColor = Color.Beige;
					inGrid[i * 2 + 2, j + 1].BackColor = Color.White;
				}
			}

			//MainForm_Temp_Grid_Write(inGrid, inDat);
		}

		public static void MainForm_Temp_Grid_Create_Name(int key, Syncfusion.Windows.Forms.Grid.GridControl inGrid, PS_Conf_Struct inDat)
		{

			int M_row = key * 4;
			int temp_no = 0;

			for (int i = 0; i < 2; i++)
			{
				for (int j = 0; j < inGrid.ColCount; j++)
				{

					if (inDat.TempEn[temp_no] == 1)
					{
						inGrid[M_row + i * 2 + 1, j + 1].Text = inDat.TempName[temp_no];
						inGrid[M_row + i * 2 + 1, j + 1].BackColor = Color.LightCyan;
						inGrid[M_row + i * 2 + 2, j + 1].BackColor = Color.White;
					}
					else
					{
						inGrid[M_row + i * 2 + 1, j + 1].Text = "";
						inGrid[M_row + i * 2 + 1, j + 1].BackColor = Color.LightGray;
						inGrid[M_row + i * 2 + 2, j + 1].BackColor = Color.LightGray;
					}
					temp_no++;
				}

			}


		}
		public static void MainForm_Temp_Grid_Write(int key, Syncfusion.Windows.Forms.Grid.GridControl inGrid, PS_Conf_Struct inDat)
		{
			int M_Row = key * 4;
			int colNo = 8;
			int ps_no = 0;
			int row = 0;

			for (int i = 0; i < 2; i++)
			{
				for (int j = 0; j < colNo; j++)
				{

					row = M_Row + i * 2 + 2;
					if (inDat.TempEn[ps_no] == 1)
					{
						inGrid[row, j + 1].Text = string.Format("{0:0}", inDat.Temp_Value[ps_no]);
						switch (inDat.Temp_Status[ps_no])
						{
							case 0://normal
								inGrid[row, j + 1].BackColor = Color.White;
								break;
							case 1://warning
								inGrid[row, j + 1].BackColor = Color.Yellow;
								break;
							case 2://protect
								inGrid[row, j + 1].BackColor = Color.Red;
								break;
						}
					}
					else
					{
						inGrid[row, j + 1].Text = "0";
						inGrid[row, j + 1].BackColor = Color.LightGray;
					}
					ps_no++;
					//if (ps_no >= inDat.TempNo ) break;
				}
			}
		}


		public static void SetupForm_Temp_Grid_Create(Syncfusion.Windows.Forms.Grid.GridControl inGrid, PS_Conf_Struct inDat)
		{

			int add = 0;

			inGrid.ColCount = 3;
			inGrid.RowCount = inDat.TempNo;
			inGrid.Properties.RowHeaders = false;
			inGrid.DefaultRowHeight = 25;

			inGrid.ColWidths[1] = 30;
			inGrid.ColWidths[2] = 80;
			inGrid.ColWidths[3] = 100;
			//inGrid.ColWidths[4] = 100;

			for (int i = 0; i < inDat.TempNo; i++)
			{
				inGrid[i + 1, 1].CellType = "CheckBox";
				//inGrid[i + 1, 2].CellType = "Static";
				for (int j = 0; j < 2; j++) inGrid[i + 1, 2 + j].CellType = "TextBox";
			}
			for (int j = 0; j < inGrid.ColCount; j++)
			{
				for (int i = 0; i < inGrid.RowCount; i++)
				{
					inGrid[i + 1, j + 1].VerticalAlignment = Syncfusion.Windows.Forms.Grid.GridVerticalAlignment.Middle;
					inGrid[i + 1, j + 1].HorizontalAlignment = Syncfusion.Windows.Forms.Grid.GridHorizontalAlignment.Center;
				}
			}
			inGrid.RowHeights[0] = 50;

			add = 1;
			inGrid[0, add++].Text = "En";
			inGrid[0, add++].Text = "Name";
			//inGrid[0, add++].Text = "Warning (oC)";
			inGrid[0, add++].Text = "Protect (oC)";

			SetupForm_Temp_Grid_Write(inGrid, inDat);

		}

		public static void SetupForm_Temp_Grid_Write(Syncfusion.Windows.Forms.Grid.GridControl inGrid, PS_Conf_Struct inDat)
		{

			for (int i = 0; i < inGrid.RowCount; i++)
			{
				if (inDat.TempEn[i] == 1)
				{
					inGrid[i + 1, 1].Text = "1";
					for (int j = 1; j < inGrid.ColCount; j++)
					{
						inGrid[i + 1, 1 + j].BackColor = Color.White;
						inGrid[i + 1, 1 + j].CellType = "TextBox";
					}
				}
				else
				{
					inGrid[i + 1, 1].Text = "0";
					for (int j = 1; j < inGrid.ColCount; j++)
					{
						inGrid[i + 1, 1 + j].BackColor = Color.LightGray;
						inGrid[i + 1, 1 + j].CellType = "Static";
					}
				}
				inGrid[i + 1, 2].Text = inDat.TempName[i];
				//inGrid[i + 1, 3].Text = inDat.TempWarning[i].ToString();
				inGrid[i + 1, 3].Text = inDat.TempProtect[i].ToString();
			}
		}

	}
}